package com.lightheart.sphr.xiaobinggan.timeselection.uitls

import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import com.lightheart.sphr.xiaobinggan.R
import com.lightheart.sphr.xiaobinggan.app.DCApplication

/**
 *    Author :hongliang
 *    E-mail : 13717858152@163.com
 *    Date   : 2021/1/54:36 PM
 *    Desc   :
 *    Version: 1.0.0
 *    自定义toast
 */
object CustomToastUtils {

    fun imgToast(title: String, img: Int, gold_pear: String, boolean: Boolean) {
        val toastDesign = Toast(DCApplication.getInstance())//创建Toast
        val layoutInflater = LayoutInflater.from(DCApplication.getInstance())//创建布局填充器
        val view = layoutInflater.inflate(R.layout.toast_item, null)//填充布局
        val llToastRoot = view.findViewById<LinearLayout>(R.id.ll_toast_root)
        llToastRoot.visibility = View.VISIBLE
        val imageView = view.findViewById<ImageView>(R.id.iv_toast_icon)//连接ImageView
        val textView = view.findViewById<TextView>(R.id.tv_toast_text)//连接TextView
        val tvTitle = view.findViewById<TextView>(R.id.tv_title)//连接TextView
        tvTitle.text = title
        if (img != 0) {
            imageView.setImageResource(img)//设置ImageView的图片
        }
        textView.text = gold_pear //设置TextView的文字
        toastDesign.view = view//添加view到Toast
        if (boolean) {//文字图片加背景居中显示
            toastDesign.setGravity(Gravity.CENTER, 0, 0)
        }
        toastDesign.show()//显示Toast
    }

    fun imgToast(title: String, gold_pear: String) {
        imgToast(title, 0, gold_pear, true)
    }
}